package com.yikes.yygh.controller;

import com.yikes.yygh.common.result.Result;
import com.yikes.yygh.controller.form.HospitalSetAddForm;
import com.yikes.yygh.controller.form.HospitalSetEditForm;
import com.yikes.yygh.controller.form.HospitalSetForm;
import com.yikes.yygh.pojo.enums.HospServiceEnums;
import com.yikes.yygh.service.HospitalSetService;
import com.yikes.yygh.web.utils.As;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 医院设置表 前端控制器
 * </p>
 *
 * @author guanrong.yin
 * @since 2025-05-01
 */
@Tag(name = "医院设置接口")
@RestController
@RequestMapping("/admin/hosp/hospital_set")
@RequiredArgsConstructor
public class HospitalSetController {

    private final HospitalSetService service;

    // 1 查询医院设置表所有信息
    @Operation(summary = "获取所有医院设置")
    @GetMapping("/findAll")
    public Result findAll() {

        return Result.ok(service.findAll());
    }

    @Operation(summary = "带条件分页查询医院设置")
    @PostMapping("/findPage")
    public Result findPage(HospitalSetForm form) {
        //调用方法实现分页查询
        return Result.ok(service.findPage(form));
    }

    @Operation(summary = "根据id获取医院设置")
    @GetMapping("/get/{id}")
    public Result getInfo(@PathVariable Long id) {

        return Result.ok(service.getInfo(id));
    }

    @Operation(summary = "添加医院设置")
    @PostMapping("/add")
    public Result add(@RequestBody HospitalSetAddForm form) {

        //调用service
        boolean save = service.add(form);
        if (save) {
            return Result.ok();
        } else {
            return Result.fail("保存失败");
        }
    }

    @Operation(summary = "修改医院设置")
    @PostMapping("/edit")
    public Result edit(@RequestBody HospitalSetEditForm form) {
        boolean flag = service.edit(form);
        if (flag) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @Operation(summary = "批量删除医院设置")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {

        As.isNotEmpty(idList, HospServiceEnums.ID_LIST_NOT_NULL);

        service.batchRemove(idList);
        return Result.ok();
    }

    @Operation(summary = "删除医院设置")
    @DeleteMapping("/del/{id}")
    public Result del(@PathVariable("id") Long id) {

        service.del(id);
        return Result.ok();
    }
}
